package com.familyaccount.model;

import lombok.Data;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Data
public class User {
    private int id;
    private String username;
    private String password;
    private String name;
    private String email;
    private String role;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    private String createdAtStr;

    // Constructor for creating new users
    public User(String username, String password, String name, String email, String role) {
        this.username = username;
        this.password = password;
        this.name = name;
        this.email = email;
        this.role = role;
    }

    // Default constructor
    public User() {
    }

    public boolean isAdmin() {
        return "ADMIN".equalsIgnoreCase(this.role) || "GOD".equalsIgnoreCase(this.role);
    }

    public boolean isGod() {
        return "GOD".equalsIgnoreCase(this.role);
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
        if (createdAt != null) {
            this.createdAtStr = createdAt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
        } else {
            this.createdAtStr = null;
        }
    }
} 